#define _CRT_SECURE_NO_WARNINGS  1
#include <stdio.h>
int main()
{
	int n = 0;
	int m = 0;
	int i = 0;
	int j = 0;
	int arr[10][10];
	scanf("%d %d ", &n, &m);
	for (i = 0; i<n; i++)
	{
		for (j= 0; j < m; j++)
		{
			scanf("%d", &arr[i][j]);
			printf("%d  ", arr[i][j]);
		}
		printf("\n");
	}
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			printf("%d ", arr[j][i]);
		}
		printf("\n");
	}
	

	return 0;
}